/**
 * <p>文件名:		MyHessianProxyFactoryBean.java</p>
 * <p>版权:		CopyrightTag</p>
 * <p>公司:		CompanyTag</p>
 * @author		周华彬(zhouhuabin@ctfo.com, zhou_hua_bin@163.com)
 */

package com.caits.lbs.framework.services.hessian.client.session;

import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URL;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.remoting.caucho.HessianClientInterceptor;

import com.caucho.hessian.client.HessianProxyFactory;
import com.caucho.hessian.io.HessianRemoteObject;

/**
 * <p>
 * MyHessianProxyFactoryBean
 * </p>
 * <p>
 * 自定义hessian代理实体类，创建自定义的代理工厂
 * </p>
 * 
 * @author 周华彬(zhouhuabin@ctfo.com, zhou_hua_bin@163.com)
 * @version 0.0.0
 *          <table style="border:1px solid gray;">
 *          <tr>
 *          <th width="100px">版本号</th>
 *          <th width="100px">动作</th>
 *          <th width="100px">修改人</th>
 *          <th width="100px">修改时间</th>
 *          </tr>
 *          <!-- 以 Table 方式书写修改历史 -->
 *          <tr>
 *          <td>0.0.0</td>
 *          <td>创建类</td>
 *          <td>zhb</td>
 *          <td>2010-11-17 上午11:52:35</td>
 *          </tr>
 *          <tr>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          </tr>
 *          </table>
 */
public class SessionHessianProxyFactoryBean extends HessianClientInterceptor
		implements FactoryBean {

	private Object serviceProxy;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.remoting.caucho.HessianProxyFactoryBean#
	 * afterPropertiesSet()
	 */
	@Override
	public void afterPropertiesSet() {
		super.afterPropertiesSet();
		SessionHessianProxy handler;
		try {
			handler = new SessionHessianProxy(new URL(getServiceUrl()),
					new HessianProxyFactory());
			this.serviceProxy = Proxy.newProxyInstance(getBeanClassLoader(),
					new Class[] { getServiceInterface(),
							HessianRemoteObject.class }, handler);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public Object getObject() {
		return this.serviceProxy;
	}

	public Class getObjectType() {
		return getServiceInterface();
	}

	public boolean isSingleton() {
		return true;
	}
}
